package org.fatmansoft.teach.repository;

import org.fatmansoft.teach.models.SocialActivity;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;


import java.util.List;
import java.util.Optional;

@Repository
public interface SocialActivityRepository extends JpaRepository<SocialActivity, Long> {

    @Query(value = "select max(socialActivityId) from SocialActivity  ")
    Integer getMaxId();


    @Query(value = "from SocialActivity  where ?1='' or socialActivityTime like %?1% ")
    List<SocialActivity> findSocialActivityListByTime(String time);

    @Query("from SocialActivity where ?1='' or socialActivityName like %?1% and socialActivityTime like %?2% ")
    List<SocialActivity> findSocialActivityListByNameTime(String name,String time);

    Optional<SocialActivity> findSocialActivityBySocialActivityNameAndSocialActivityTime(String name, String time);

    @Query("from SocialActivity where ?1='' or socialActivityName like %?1% or socialActivityType like %?1% ")
    List<SocialActivity> findSocialActivityByNameType(String nameType);

    @Modifying
   @Query("delete  from SocialActivity where socialActivityName like %?1% and socialActivityTime like %?2% ")
    void deleteBySocialActivityNameAndSocialActivityTime(String name,String time);


}
